package com.bcx.crm.java.collection.sortAlgorithm;

/**
 * Created by ys on 2018/3/2.
 * 冒泡排序算法
 */
public class BubbleSort {
    public static void main(String[] args) {
        int [] a = new int[]{55,4,6,1,99,55,33,666};
        //n个数，比较的轮数是n-1轮，外循环控制比较的轮数
        for (int i=0;i<a.length-1;i++){
            //每一轮比较的次数是n-1-i次
            for (int j=0;j<a.length-1-i;j++){
                //两两比较小靠前
                if (a[j]>a[j+1]){
                    //两数做交换
                    int temp =  a[j];
                    a[j] = a[j+1];
                    a[j+1] = temp;
                }
            }
        }
        System.out.println();
        for (int a1:a){
            System.out.print(a1+",");
        }
    }
}
